<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        body {
            background-color: rgb(241, 242, 243);
        }

        .el-header {
            background-color: white;
        }

        .center {
            width: 1200px;
            margin: 0 auto
        }

        footer h3 {
            color: white;
        }

        #footer_center p {
            margin: 0;
        }

        /*因为el-card是由多个div组成的,直接通过类选择器只能选择到外层的div
        而自带的内边距是内层div添加的,所以需要通过子元素选择器*/
        .right_top_card > div {
            padding: 0;
        }

        .title_p {
            height: 40px;
            overflow: hidden;
            /*设置超出的部分用省略号展示*/
            display: -webkit-box;
            -webkit-line-clamp: 2; /*设置显示的行数*/
            -webkit-box-orient: vertical; /*设置纵向排列*/
            margin: 0;
        }

        a {
            text-decoration: none;
            color: black;
        }

        a:hover {
            color: orange;
        }
    </style>
</head>
<body>
<div id="app">
    <el-container>
        <my-header></my-header>
        <el-main class="center" style="margin-top: 30px">
            <el-row gutter="20">
                <el-col span="18">
                    <el-card>
                        <h2 style="color: orange;text-align: center">
                            {{c.title}}
                        </h2>
                        <p style="font-size: 12px;color: #666;text-align: center ">
                            作者:{{c.nickName}} | 发布时间:{{c.createTime}} | 阅读次数:{{c.viewCount}}
                        </p>
                        <el-divider></el-divider>
                        <div v-if="c.type!=2">
                            <el-card style="font-size: 12px;">
                                <b style="color: #409EFF">摘要:</b>
                                {{c.brief}}
                            </el-card>
                            <p v-html="c.content"></p>
                        </div>
                        <div v-else>
                            <video style="width: 100%" :src="c.videoUrl"
                                   controls type="video/mp4"></video>
                        </div>
                    </el-card>
                    <!--评论相关开始-->
                    <el-card>
                        <p>发一条友善的评论</p>
                        <el-divider></el-divider>
                        <el-row gutter="20">
                            <el-col span="20">
                                <el-input type="textarea" v-model="comment.content" placeholder="说点儿啥..."></el-input>
                            </el-col>
                            <el-col span="4">
                                <el-button @click="post()">发布</el-button>
                            </el-col>
                        </el-row>
                        <el-row v-for="c in commentArr" style="margin-top: 20px">
                            <el-col span="2">
                                <el-avatar :src="c.userImgUrl"></el-avatar>
                            </el-col>
                            <el-col span="22">
                                <span style="font-weight: bold;color: orange">{{c.nickName}}:</span>
                                <p style="margin: 5px 0">{{c.content}}</p>
                                <span style="font-size: 12px;color: #666">{{c.createTime}}</span>
                            </el-col>
                        </el-row>
                    </el-card>
                    <!--评论相关结束-->
                </el-col>
                <el-col span="6">
                    <el-card class="right_top_card">
                        <div style="background-image: url('imgs/avarbg.jpg');height: 90px">
                        </div>
                        <div style="text-align: center;position: relative;bottom: 50px">
                            <img :src="c.userImgUrl" style="
                        width: 90px;height: 90px;border-radius: 90px;border:5px solid white">
                            <p style="font-size: 20px;margin: 0;font-weight: bold">{{c.nickName}}</p>
                            <i class="el-icon-edit">本文作者</i><br>
                            <i class="el-icon-time">{{c.createTime}}</i>
                        </div>
                    </el-card>
                    <!--作者其它文章开始-->
                    <el-card style="margin: 10px 0">
                        <h3>作者其它文章</h3>
                        <el-divider></el-divider>
                        <el-row gutter="10" v-for="c in otherArr">
                            <el-col span="10">
                                <a :href="'/detail.html?id='+c.id">
                                    <img :src="c.imgUrl" width="100%" height="70px">
                                </a>
                            </el-col>
                            <el-col span="14">
                                <a :href="'/detail.html?id='+c.id">
                                    <p class="title_p">{{c.title}}</p>
                                </a>
                                <i class="el-icon-time">{{c.createTime}}</i>
                            </el-col>
                        </el-row>
                    </el-card>
                    <!--作者其它文章结束-->
                    <!--热门文章开始-->
                    <el-card style="margin: 10px 0">
                        <h3>热门文章</h3>
                        <el-divider></el-divider>
                        <el-row gutter="10" v-for="c in hotArr">
                            <el-col span="10">
                                <a :href="'/detail.html?id='+c.id">
                                    <img :src="c.imgUrl" width="100%" height="70px">
                                </a>
                            </el-col>
                            <el-col span="14">
                                <a :href="'/detail.html?id='+c.id">
                                    <p class="title_p">{{c.title}}</p>
                                </a>
                                <i class="el-icon-time">{{c.createTime}}</i>
                            </el-col>
                        </el-row>
                    </el-card>
                    <!--热门文章结束-->
                </el-col>
            </el-row>

        </el-main>
        <el-footer style="background-color: #2f3234;
        height: 280px;padding: 50px 0">
            <div class="center" style="color: #666;text-align: center">
                <el-row gutter="20">
                    <el-col span="8">
                        <img src="imgs/icon.png">
                        <p>教程灵感就看烘焙坊</p>
                        <p>烘焙行业网络社区平台</p>
                        <p>全国百城上千个职位等你来</p>
                    </el-col>
                    <el-col span="8">
                        <el-row id="footer_center">
                            <el-col span="8">
                                <h3>关于我们</h3>
                                <p>关于我们</p>
                                <p>烘焙学院</p>
                                <p>烘焙食谱</p>
                                <p>分类信息</p>
                                <p>求职招聘</p>
                                <p>社区交流</p>
                            </el-col>
                            <el-col span="8">
                                <h3>服务与支持</h3>
                                <p>联系我们</p>
                                <p>广告投放</p>
                                <p>用户协议</p>
                                <p>友情链接</p>
                                <p>在线反馈</p>
                                <p>我发投稿</p>
                            </el-col>
                            <el-col span="8">
                                <h3>底部导航</h3>
                                <p>Archiver</p>
                                <p>手机版</p>
                                <p>小黑屋</p>
                            </el-col>
                        </el-row>
                    </el-col>
                    <el-col span="8">
                        <div style="font-size: 60px;">
                            <span style="color: orange">烘焙</span>坊
                        </div>
                        <p>烘焙行业网络社区平台</p>
                    </el-col>
                </el-row>
            </div>
        </el-footer>
    </el-container>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<!--引入Axios-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script src="js/my-header.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                c: {
                    "id": 18,
                    "title": "爆浆抹茶甜甜圈面包，自带幸福感的小甜甜",
                    "brief": "爆浆抹茶甜甜圈面包好吃的起飞的爆浆抹茶甜甜圈，从里到外被抹茶包裹着，自带幸福感的小甜甜，抹茶控们完全",
                    "videoUrl": "imgs/7c1ec29b-77fb-4880-ac95-0decacfb95be.mp4",
                    "imgUrl": "imgs/3daca90c-a075-48bb-bead-5f89bbdd42f8.jpg",
                    "content": "<p style=\"text-align: start;\"><span style=\"color: rgb(42, 165, 59);\"><strong>爆浆抹茶甜甜圈面包好吃的起飞的爆浆抹茶甜甜圈，从里到外被抹茶包裹着，自带幸福感的小甜甜，抹茶控们完全抵抗不了的清新味道，我已经沦陷了～</strong></span></p><p style=\"text-align: start;\"> </p><p style=\"text-align: start;\"><span style=\"color: rgb(42, 165, 59);\"><strong>爆浆抹茶甜甜圈面包的用料</strong></span></p><p style=\"text-align: start;\"><span style=\"color: rgb(19, 110, 194);\"><u>中种</u></span><span style=\"color: rgb(19, 110, 194);\">面团，面包粉200g，鸡蛋46g，酵母3g，牛奶90g，主面团，面包粉80g，砂糖40g，盐3g，酵母1.5g，水25g，黄油25g， 抹茶主厨奶油馅 ，抹茶粉5g，热水10g，蛋黄2个，牛奶250毫升，砂糖20g，玉米淀粉10g，椰子油10g，淡奶油100g，表面抹茶粉 砂糖适量</span></p><p style=\"text-align: start;\"> </p><p style=\"text-align: start;\"><span style=\"color: rgb(42, 165, 59);\"><strong>爆浆抹茶甜甜圈面包的做法</strong></span></p><p style=\"text-align: start;\"><img src=\"https://hongbeiguan.com/data/attachment/portal/202007/17/181653o0xhzxpdqzx42oxd.jpg\" alt=\"\" data-href=\"\" style=\"height: auto;\"></p><p style=\"text-align: start;\"><span style=\"color: rgb(42, 165, 59);\"><strong>步骤1</strong></span>:将中种面团材料全部混合和成面团，表面光滑不粘手.</p><p style=\"text-align: start;\"> </p><p style=\"text-align: start;\"><img src=\"https://hongbeiguan.com/data/attachment/portal/202007/17/181653n03zc89ai838o4gg.jpg\" alt=\"\" data-href=\"\" style=\"height: auto;\"></p><p style=\"text-align: start;\"><span style=\"color: rgb(42, 165, 59);\"><strong>步骤2</strong></span>:放入冰箱冷藏一夜8-12小时</p><p style=\"text-align: start;\"> </p><p style=\"text-align: start;\"><img src=\"https://hongbeiguan.com/data/attachment/portal/202007/17/181654l9nyswrrp2n9npnr.jpg\" alt=\"\" data-href=\"\" style=\"height: auto;\"></p><p style=\"text-align: start;\"><span style=\"color: rgb(42, 165, 59);\"><strong>步骤3</strong></span>:牛奶放入锅中，煮至83度.</p><p style=\"text-align: start;\"> </p><p style=\"text-align: start;\"><img src=\"https://hongbeiguan.com/data/attachment/portal/202007/17/181654bdhgaspzppvzlgz9.jpg\" alt=\"\" data-href=\"\" style=\"height: auto;\"></p><p style=\"text-align: start;\"><span style=\"color: rgb(42, 165, 59);\"><strong>步骤4</strong></span>:鸡蛋放入碗中搅散，放入砂糖，玉米淀粉. 搅匀 .</p><p style=\"text-align: start;\"> </p><p style=\"text-align: start;\"><img src=\"https://hongbeiguan.com/data/attachment/portal/202007/17/181654hbdsdxeqt5mqe4qq.jpg\" alt=\"\" data-href=\"\" style=\"height: auto;\"></p><p style=\"text-align: start;\"><span style=\"color: rgb(42, 165, 59);\"><strong>步骤5</strong></span>:倒入蛋黄中，先少量到入搅匀.在慢慢全部倒入搅匀.</p><p style=\"text-align: start;\"> </p><p style=\"text-align: start;\"><img src=\"https://hongbeiguan.com/data/attachment/portal/202007/17/181654w95ett956fr2foft.jpg\" alt=\"\" data-href=\"\" style=\"height: auto;\"></p><p style=\"text-align: start;\"><span style=\"color: rgb(42, 165, 59);\"><strong>步骤6</strong></span>:倒回锅中小火煮，要不停的搅防止糊底. 煮至非常粘稠的状态.</p><p style=\"text-align: start;\"> </p><p style=\"text-align: start;\"><img src=\"https://hongbeiguan.com/data/attachment/portal/202007/17/181654f4rkfu45hd25f75t.jpg\" alt=\"\" data-href=\"\" style=\"height: auto;\"></p><p style=\"text-align: start;\"><span style=\"color: rgb(42, 165, 59);\"><strong>步骤7</strong></span>:抹茶粉加热水搅匀，倒入锅中搅拌均匀.</p><p style=\"text-align: start;\"> </p>",
                    "type": 1,
                    "viewCount": 17,
                    "commentCount": 1,
                    "createTime": "2023/03/28 16:20:26",
                    "nickName": "汤姆",
                    "userImgUrl": "imgs/b9c21937-d7f8-4843-8f53-7eb9d979829a.jpg",
                    "userId": 12
                },
                otherArr: [{
                    "id": 27,
                    "title": "aaa",
                    "imgUrl": "imgs/1.jpg",
                    "createTime": "2023/05/11"
                },
                    {
                        "id": 26,
                        "title": "85度C又出事了，饮品里喝出“订书针”，店员的一波操作让女子直接曝光！",
                        "imgUrl": "imgs/f8b8c3a9-ccb0-4531-a78b-dd1b2a69d02c.jpg",
                        "createTime": "2023/03/28"
                    },
                    {
                        "id": 25,
                        "title": "济南一知名品牌面包连锁店，多家门店关门，很多人充值卡还没消费完，记者调查发现... ...",
                        "imgUrl": "imgs/b032b739-5be1-4ad1-a028-ab914caed4f9.jpg",
                        "createTime": "2023/03/28"
                    },
                    {
                        "id": 24,
                        "title": "烘焙行业越来越难做了？并不是",
                        "imgUrl": "imgs/a19bedd0-df90-4aa5-9f80-966ce7e5135c.jpg",
                        "createTime": "2023/03/28"
                    }],
                hotArr: [{
                    "id": 18,
                    "title": "爆浆抹茶甜甜圈面包，自带幸福感的小甜甜",
                    "imgUrl": "imgs/3daca90c-a075-48bb-bead-5f89bbdd42f8.jpg",
                    "createTime": "2023/03/28"
                },
                    {
                        "id": 17,
                        "title": "心形火龙果椰蓉面包,任谁都抗拒不了",
                        "imgUrl": "imgs/15fcffb1-3ef5-41dc-87d4-514469e10bdd.jpg",
                        "createTime": "2023/03/28"
                    },
                    {
                        "id": 11,
                        "title": "入口即酥的超浓花生酱酥饼a",
                        "imgUrl": "imgs/0237dcfc-9f6a-47cd-b45e-59a5897f2992.jpg",
                        "createTime": "2023/03/27"
                    },
                    {
                        "id": 27,
                        "title": "aaa",
                        "imgUrl": "imgs/1.jpg",
                        "createTime": "2023/05/11"
                    }],
                comment: {content: ""},
                commentArr: [{
                    "id": 30,
                    "content": "aaa",
                    "nickName": "杰瑞",
                    "userImgUrl": "imgs/1.jpg",
                    "createTime": "2023/05/26 09:17:14"
                },
                    {
                        "id": 26,
                        "content": "自己做了一遍,还不错!!",
                        "nickName": "汤姆",
                        "userImgUrl": "imgs/b9c21937-d7f8-4843-8f53-7eb9d979829a.jpg",
                        "createTime": "2023/03/30 16:51:02"
                    },
                    {
                        "id": 23,
                        "content": "看起来挺好吃",
                        "nickName": "汤姆",
                        "userImgUrl": "imgs/b9c21937-d7f8-4843-8f53-7eb9d979829a.jpg",
                        "createTime": "2023/03/30 16:12:27"
                    }]
            }
        },
        methods: {
            post() {
                if (v.comment.content.trim() == "") {
                    v.$message.error("请输入评论的内容!");
                    return;
                }
                let user = localStorage.user ? JSON.parse(localStorage.user) : null;
                if (user == null) {
                    alert("请先登录!");
                    location.href = "./login.html";
                    return;
                }
                //作者id和文章id
                v.comment.userId = user.id;
                v.comment.contentId = v.c.id;
                //发请求
                axios.post("/v1/comments/add-new", v.comment).then(function (response) {
                    if (response.data.code == 1) {
                        alert("评论完成!");
                        v.comment.content = "";
                        v.loadComments(v.c.id);
                    } else {
                        alert("登录超时,请重新登录!");
                        location.href = "./login.html";
                    }
                })
            },
            loadComments(id) {
                //请求当前文章相关的评论数据
                axios.get("/v1/comments/" + id).then(function (response) {
                    if (response.data.code == 1) {
                        v.commentArr = response.data.data;
                    }
                })
            }
        },
        created: function () {

            //请求热门文章
            axios.get("/v1/contents/hot").then(function (response) {
                if (response.data.code == 1) {
                    v.hotArr = response.data.data;
                }
            })
            let id = new URLSearchParams(location.search).get("id");
            axios.get("/v1/contents/" + id + "/detail").then(function (response) {
                if (response.data.code == 1) {
                    v.c = response.data.data;
                    console.log(v.c);
                    //加载作者其它文章
                    axios.get("/v1/contents/" + v.c.userId + "/other").then(function (response) {
                        if (response.data.code == 1) {
                            v.otherArr = response.data.data;
                        }
                    })
                }
            })
            this.loadComments(id);
        }
    })
</script>
</html>